package cn.ljy.authority.web.controller.backstage.authority;


import cn.ljy.authority.model.SysDepartment;
import cn.ljy.authority.model.query.SysDepartmentQuery;
import cn.ljy.authority.service.SysDepartmentService;
import cn.ljy.authority.web.controller.backstage.BaseBackstageController;
import cn.ljy.common.model.result.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "后台部门模块")
@RestController
@RequestMapping(value = "/backstage/authority/department")
public class SysDepartmentController extends BaseBackstageController<SysDepartment, SysDepartmentQuery,Long> {

    @Autowired
    private SysDepartmentService baseService;

    @Override
    public String getAuthorityPrefix() {
        return "sys:department"; // 定义模块权限前缀
    }

//    @ApiOperation(value = "添加部门")
//    @PreAuthorize("hasAuthority('sys:department:add')")
//    @Override
//    protected ResponseData add(@Validated({AddWorkValidation.class}) @RequestBody SysDepartment sysDepartment) {
//        return super.add(sysDepartment);
//    }
//
//    @ApiOperation(value = "读取部门指定信息")
//    @PreAuthorize("hasAuthority('sys:department:query')")
//    @Override
//    protected ResponseData get(@PathVariable Long id) {
//        return super.get(id);
//    }
//
//
//    @ApiOperation(value = "编辑部门")
//    @PreAuthorize("hasAuthority('sys:department:edit')")
//    @Override
//    public ResponseData edit(@Validated({UpdateWorkValidation.class}) @RequestBody SysDepartment sysDepartment){
//        return super.edit(sysDepartment);
//    }
//
//    @ApiOperation(value = "批量删除指定的多个部门")
//    @PreAuthorize("hasAuthority('sys:department:del')")
//    @Override
//    public ResponseData deletes(Long[] ids){
//        return super.deletes(ids);
//    }

    //=========================扩展部分=============================================//

    @ApiOperation(value = "部门的树形列表")
    @GetMapping("/tree")
    @PreAuthorize("hasAuthority('sys:department:query')")
    public ResponseData tree(SysDepartmentQuery sysDepartmentQuery){
        List<SysDepartment> sysDepartments = baseService.findTree(sysDepartmentQuery);
        return ResponseData.success(sysDepartments);
    }
}
